﻿CREATE Trigger t_ImageType_Insert
On dbo.t_ImageType
For Insert,Update,delete
As

Declare @ID int,@TabIndex int

IF trigger_nestlevel() > 1 Return

SELECT @ID = ID,@TabIndex = TabIndex FROM inserted

IF Not @TabIndex Is Null
BEGIN
	IF Update(TabIndex)
		UPDATE t_ImageType
		SET TabIndex = TabIndex + 1	WHERE (TabIndex >= @TabIndex) AND ID <> @ID
	RETURN
END

UPDATE t_ImageType
SET TabIndex = TabIndex - 1	WHERE (TabIndex >= (SELECT TabIndex FROM deleted))
